package com.zjuh.goodboy.util;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DropOffLinkedBlockingQueue<E> extends LinkedBlockingQueue<E> {

	private static final long serialVersionUID = -5632461772872998981L;

	private transient static final Logger logger = LoggerFactory.getLogger(DropOffLinkedBlockingQueue.class);
	
	public DropOffLinkedBlockingQueue(int capacity) {
		super(capacity);
	}

	@Override
	public boolean offer(E e, long timeout, TimeUnit unit)
			throws InterruptedException {
		logger.info("remainingCapacity "+ remainingCapacity() +" :" + e);
		if (this.remainingCapacity() <= 0) {
			return false;
		}
		return super.offer(e, timeout, unit);
	}

	@Override
	public boolean offer(E e) {
		logger.info("remainingCapacity "+ remainingCapacity() +" :" + e);
		if (this.remainingCapacity() <= 0) {
			return false;
		}
		return super.offer(e);
	}

}
